package alkaid.eis.sys.controller;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import alkaid.eis.sys.entity.Dept;
import lombok.Getter;
import lombok.Setter;

/**
 * 部门平面传输对象
 * 
 * @author Lucky Yang
 * @since 0.0.1
 */
@Getter
@Setter
public class DeptFlatDto {
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;
    private String parentName;
    private Boolean parentEnabled;
    private Integer parentOrderNo;
    private Integer parentChildCount;
    private String parentPathId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    private String name;
    private Boolean enabled;
    private Integer orderNo;
    private Integer childCount;
    private String pathId;

    public static DeptFlatDto of(Dept source) {
        DeptFlatDto rslt = new DeptFlatDto();

        rslt.setId(source.getId());
        rslt.setName(source.getName());
        rslt.setEnabled(source.getEnabled());
        rslt.setOrderNo(source.getOrderNo());
        rslt.setChildCount(source.getChildCount());
        rslt.setPathId(source.getPathId());

        Dept parent = source.getParent();
        if (parent != null) {
            rslt.setParentId(parent.getId());
            rslt.setParentName(parent.getName());
            rslt.setParentEnabled(parent.getEnabled());
            rslt.setParentOrderNo(parent.getOrderNo());
            rslt.setParentChildCount(parent.getChildCount());
            rslt.setParentPathId(parent.getPathId());
        }
        return rslt;
    }
}
